package com.henry.imkit

import android.content.Context
import androidx.fragment.app.FragmentActivity
import com.henry.imkit.models.RealmHelper
import com.henry.imkit.request.IMRetrofit

class IMKit {

    companion object {
        val instance: IMKit by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            IMKit() }
    }

    lateinit var context: Context
    lateinit var activity: FragmentActivity

    var domain = ""

    fun initKit(context: Context, domain: String? = null) {
        this.context = context
        if (context is FragmentActivity) {
            activity = context
        }

        this.domain = domain.toString()

        IMRetrofit.updateService(domain ?: "")

    }

    fun onDestroy() {
        if (domain.isNotEmpty()) {
            domain = ""
            IMManager.onDestroy()
            IMRetrofit.onDestroy()
            RealmHelper.onDestroy()
        }
    }

}